/*     */ package com.zimbra.cs.index;
/*     */ 
/*     */ import com.google.common.io.Closeables;
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.SoapProtocol;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.AuthToken;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import java.io.IOException;
/*     */ import java.util.Collections;
/*     */ import java.util.List;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ final class RemoteQueryOperation
/*     */   extends FilterQueryOperation
/*     */ {
/*  40 */   private ProxiedQueryResults results = null;
/*  41 */   private QueryTarget queryTarget = null;
/*     */   
/*     */   public long getCursorOffset()
/*     */   {
/*  45 */     return -1L;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   boolean tryAddOredOperation(QueryOperation op)
/*     */   {
/*  54 */     Set<QueryTarget> targets = op.getQueryTargets();
/*  55 */     assert (QueryTarget.getExplicitTargetCount(targets) == 1);
/*  56 */     assert (QueryTarget.hasExternalTarget(targets));
/*     */     
/*  58 */     for (QueryTarget target : targets) {
/*  59 */       assert (target != QueryTarget.LOCAL);
/*  60 */       if (target != QueryTarget.UNSPECIFIED) {
/*  61 */         if (this.queryTarget == null) {
/*  62 */           this.queryTarget = target;
/*  63 */         } else if (!this.queryTarget.equals(target)) {
/*  64 */           return false;
/*     */         }
/*     */       }
/*     */     }
/*     */     
/*  69 */     assert (this.queryTarget != null);
/*     */     
/*  71 */     if (this.operation == null) {
/*  72 */       this.operation = new UnionQueryOperation();
/*     */     }
/*  74 */     ((UnionQueryOperation)this.operation).add(op);
/*  75 */     return true;
/*     */   }
/*     */   
/*     */   public String toString()
/*     */   {
/*  80 */     return "REMOTE[" + this.queryTarget + "]:" + this.operation;
/*     */   }
/*     */   
/*     */   protected void setup(SoapProtocol proto, AuthToken authToken, SearchParams params) throws ServiceException {
/*  84 */     Provisioning prov = Provisioning.getInstance();
/*  85 */     Account acct = prov.get(Key.AccountBy.id, this.queryTarget.toString(), authToken);
/*  86 */     if (acct == null) {
/*  87 */       throw AccountServiceException.NO_SUCH_ACCOUNT(this.queryTarget.toString());
/*     */     }
/*     */     
/*  90 */     Server remoteServer = prov.getServer(acct);
/*     */     
/*  92 */     String queryString = this.operation.toQueryString();
/*  93 */     if (ZimbraLog.search.isDebugEnabled()) {
/*  94 */       ZimbraLog.search.debug("RemoteQuery=\"%s\" target=%s server=%s", new Object[] { queryString, this.queryTarget, remoteServer.getName() });
/*     */     }
/*     */     
/*     */ 
/*  98 */     this.results = new ProxiedQueryResults(proto, authToken, this.queryTarget.toString(), remoteServer.getName(), params, queryString, params.getFetchMode());
/*     */   }
/*     */   
/*     */   public void resetIterator()
/*     */     throws ServiceException
/*     */   {
/* 104 */     if (this.results != null) {
/* 105 */       this.results.resetIterator();
/*     */     }
/*     */   }
/*     */   
/*     */   public ZimbraHit getNext() throws ServiceException
/*     */   {
/* 111 */     return this.results != null ? this.results.getNext() : null;
/*     */   }
/*     */   
/*     */   public ZimbraHit peekNext() throws ServiceException
/*     */   {
/* 116 */     return this.results != null ? this.results.peekNext() : null;
/*     */   }
/*     */   
/*     */   public void close() throws IOException
/*     */   {
/* 121 */     Closeables.closeQuietly(this.results);
/* 122 */     super.close();
/*     */   }
/*     */   
/*     */   public List<QueryInfo> getResultInfo()
/*     */   {
/* 127 */     if (this.results != null) {
/* 128 */       return this.results.getResultInfo();
/*     */     }
/* 130 */     return Collections.emptyList();
/*     */   }
/*     */   
/*     */ 
/*     */   public boolean isPreSorted()
/*     */   {
/* 136 */     return this.results.isPreSorted();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/index/RemoteQueryOperation.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */